home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <graphics.h>
- /* Define array of colors using defined constants from
- * graphics.h
- */
- int colors[] =
- { EGA_BLACK, EGA_BLUE, EGA_GREEN, EGA_CYAN, EGA_RED,
- EGA_MAGENTA, EGA_BROWN, EGA_LIGHTGRAY,
- EGA_DARKGRAY, EGA_LIGHTBLUE, EGA_LIGHTGREEN,
- EGA_LIGHTCYAN, EGA_LIGHTRED, EGA_LIGHTMAGENTA,
- EGA_YELLOW, EGA_WHITE};
-
- main()
- {
- int graphdriver = DETECT, graphmode, i=0;
-
- /* Detect and initialize graphics system */
- initgraph(&graphdriver, &graphmode, "c:\\turboc");
- if (graphdriver != EGA && graphdriver != VGA)
- {
- /* Error setting mode */
- closegraph();
- printf("Not EGA/VGA hardware\n");
- exit(0);
- }
- setcolor(1);
- outtextxy(10,10, "Demonstrating setpalette");
- /* Loop through several colors for pixel
- * values 0 and 1
- */
- outtextxy(10,20, "press any key to go on, 'q' to exit");
- while(1)
- {
- if (getch() == 'q')
- {
- /* Reset graphics environment */
- closegraph();
- exit(0);
- }
- /* Alter pixel value 0 and 1 */
- setpalette(0, colors[i%16]);
- setpalette(1, colors[(i+2)%16]);
- /* Select next color from array */
- i++;
- }
- }